<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of Captcha
 *
 * @author chaporgin_a
 */
class VA_Form_Validator_Captcha extends VA_Form_Validator {
  protected $securImageIncludePath = null;
  public function init($options){
    parent::init($options);
    $this->securImageIncludePath = 
            $this->getOption('includePath', JPATH_COMPONENT.DIRECTORY_SEPARATOR.join(DIRECTORY_SEPARATOR, array('captchas','securimage.php')));
  }
  public function isValid($value) {
    require_once $this->securImageIncludePath;
    $securimage = new Securimage();
    $securimage->use_sqlite_db = TRUE;
    $securimage->sqlite_database = $_SERVER['DOCUMENT_ROOT'].
        DIRECTORY_SEPARATOR.join(DIRECTORY_SEPARATOR, array('components','com_electroforms','captchas', 'database', 'securimage.sqlite'));
//    var_dump($securimage->sqlite_database);exit;
    $this->errorMessages = array();
    if($securimage->check($value) == false) {
      $this->errorMessages[] = 'Попробуйте ввести символы еще раз';
      return FALSE;
    }
    return TRUE;
  }

  public function getHTMLTagAttributes() {
    return array('minlength' => array(6), 'maxlength' => array(6));
  }
}

